/**
*  \file var_tbl.h
*
*  \brief
*
*  \authors Dajin Li  dajin.li@linde-.de
*
*
*
*/


#ifndef _VAR_TBL
#define _VAR_TBL
/*================================================[ public includes  ]================================================*/

#include "stm32f10x.h"
#include "rtc.h"
#include "Global.h"
#include "top.h"
#include "CAN_canopen.h"


/*================================================[ public defines   ]================================================*/
#define VAR_PART_NUMBER_INDEX              0
#define VAR_TECH_PWD_INDEX                 20
#define VAR_SER_PWD_INDEX                  21
#define VAR_UNITS_INDEX                    22
#define VAR_DATE_FORMAT_INDEX              24
#define VAR_HOUR_FORMAT_INDEX              25
#define VAR_LAST_PARTNUMBER_INDEX          27
#define VAR_TIME_STAMP_RST_INDEX           30
#define VAR_TIME_STAMP_RST_HIS_INDEX       31
#define VAR_LAGUAGE_INDEX                  32
#define VAR_USER_DIGICODEARRAY1            38
#define VAR_USER_DIGICODEARRAY2            39
#define VAR_USER_DIGICODEARRAY3            40
#define VAR_USER_DIGICODEARRAY4            41
#define VAR_USER_DIGICODEARRAY5            42
#define VAR_USER_DIGICODEARRAY6            43
#define VAR_USER_DIGICODEARRAY7            44
#define VAR_USER_DIGICODEARRAY8            45
#define VAR_HOURMETER_DISPLAY_INDEX        50
#define VAR_CLK_DISPLAY_INDEX              52
#define VAR_CUSTOMIZED_MSG1_INDEX          63
#define VAR_CUSTOMIZED_MSG2_INDEX          64
#define VAR_CUSTOMIZED_MSG3_INDEX          65
#define VAR_CUSTOMIZED_MSG4_INDEX          66
#define VAR_CUSTOMIZED_MSG5_INDEX          67
#define VAR_CUSTOMIZED_MSG6_INDEX          68
#define VAR_CUSTOMIZED_MSG7_INDEX          69
#define VAR_CUSTOMIZED_MSG8_INDEX          70
#define VAR_CUSTOMIZED_MSG9_INDEX          71
#define VAR_CUSTOMIZED_MSG10_INDEX         72
#define VAR_ACTIVE_OSHA_MSG1_INDEX         73
#define VAR_ACTIVE_OSHA_MSG2_INDEX         74
#define VAR_OSHA_MSG_SHOWED_INDEX          75
#define VAR_STEER_HOURS_INDEX              83
#define VAR_MOTOR_HOURS_INDEX              84
#define VAR_SEAT_HOURS_INDEX               85
#define VAR_KEYON_HOURS_INDEX              86
#define VAR_STORED_FAULT0_INDEX            87
#define VAR_TRUCK_TYPE_INDEX               112
#define VAR_LCD_BKLIGHT_INDEX              124
#define VAR_STORED_FAULT1_INDEX            125
#define VAR_DAYLIGHT_SAVING_INDEX          144
#define VAR_SAFETY_SPD_INDEX               165
#define VAR_MAX_TRACTION_SPD_BACK_INDEX    166
#define VAR_MAX_TRACTION_SPD_FORW_INDEX    167
#define VAR_DISPLAY_OPTIONS_INDEX          184
#define VAR_FUEL_SNS_TYPE_INDEX            185
#define VAR_CREEP_SPD_INDEX                186
#define VAR_STORED_FAULT2_INDEX            187
#define VAR_SEAT_BELT_INDEX                203
#define VAR_CHANGE_ENG_OIL_INDEX           205
#define VAR_CHANGE_AIR_FILTER_INDEX        206
#define VAR_CHANGE_SERVICE_ENG_INDEX       207
#define VAR_CHANGE_SERVICE_MACHINE_INDEX   208
#define VAR_STATUS_SEL1_INDEX              211
#define VAR_STATUS_SEL2_INDEX              212
#define VAR_CHANGE_ENG_OIL_MONTH_INDEX     213
#define VAR_CHANGE_AIR_FILTER_MONTH_INDEX  214
#define VAR_SER_ENG_MONTH_INDEX            215
#define VAR_SER_MACHINE_MONTH_INDEX        216
#define VAR_TRACTION_SPD_KP_INDEX          217
#define VAR_TRACTION_SPD_KI_INDEX          218
#define VAR_AREA_BACK_SPD_DLY_INDEX        219
#define VAR_ACCEL_DECEL_INDEX              220
#define VAR_RFID_TIMEOUT_INDEX             221
#define VAR_PIN_EN_INDEX                   222
#define VAR_AREA_SPEED_LIMIT_INDEX         223
#define VAR_STORED_FAULT3_INDEX            225

#define VAR_POINT1_VOLTS_INDEX             241
#define VAR_POINT2_VOLTS_INDEX             242
#define VAR_POINT3_VOLTS_INDEX             243
#define VAR_MAX_REVERSE_SPD_INDEX          244
#define VAR_POINT1_DISTANCE_INDEX          245
#define VAR_POINT2_DISTANCE_INDEX          246
#define VAR_POINT3_DISTANCE_INDEX          247


#define POINT3_VOLTS_DEF                   10000
#define POINT2_VOLTS_DEF                   8832
#define POINT1_VOLTS_DEF                   6614

#define PIN_CODE_FAULT                     BIT0
#define ENG_CHK_FAULT                      BIT1
#define SPD_SNS_FAULT                      BIT2
#define BR1219_PEDAL_RATIO_LIMIT_FAULT     BIT3

#define CAN2_BUSOFF_FAULT                  BIT31
#define CAN1_BUSOFF_FAULT                  BIT30
#define EE_FAULT                           BIT29
#define HIGH_VOLT_FAULT                    BIT28
#define LOW_VOLT_FAULT                     BIT27
#define EXT_ACT_FAULT                      BIT26
#define RFID_SWITCH_LIMIT_FAULT            BIT25
#define RFID_TIMEOUT_FAULT                 BIT24
#define RFID_MARK_FAULT                    BIT23
#define MAINT_FAULT                        BIT22    

#define CANOPEN_BUSOFF_FAULT_CODE          0x0262
#define J1939_BUSOFF_FAULT_CODE            0x0261
#define RFID_MARK_FAULT_CODE               0x0106
#define RFID_TIMEOUT_FAULT_CODE            0x0105
#define SPD_SNS_FAULT_CODE                 0x0104
#define EE_FAULT_CODE                      0x0103
#define HIGH_VOLT_FAULT_CODE               0x0102
#define LOW_VOLT_FAULT_CODE                0x0101
#define BR1219_PEDAL_RATIO_LIMIT_CODE      0x0301

#define VAR_SCALE_DIV_10                   1
#define VAR_SCALE_MUL_10                   2
#define VAR_SCALE_TIME                     3
#define VAR_SCALE_RPM                      4
#define VAR_SCALE_SWITCH                   5
#define VAR_SCALE_PEDAL                    6
#define VAR_SCALE_MUL_100                  7
#define VAR_SCALE_MUL_16                   8
#define VAR_SCALE_DIV_255                  9


#define VAR_SCALE_ON_OFF                   30
#define VAR_SCALE_HANDLE_SEAT              31
#define VAR_SCALE_OPERATING_HOURM          32
#define VAR_SCALE_SEATBELT_TYPE            33
#define VAR_SCALE_HOUR_COUNTER             34
#define VAR_SCALE_AUX_OUTPUT1              35
#define VAR_SCALE_SET_MOT                  36
#define VAR_SCALE_HYDO_TYPE                37
#define VAR_SCALE_BATT_TYPE                38
#define VAR_SCALE_MC                       39
#define VAR_SCALE_PERFORMANCE_MODE		   40
#define VAR_SCALE_CAL            		   41
#define VAR_SCALE_VOLTS            		   42
#define MIN_STATUS_SEL                     1
#define MAX_STATUS_SEL                     7

#define DEF_RST_TYPE_FLAG                  0xFFFF
#define DEF_INIT_KEYON_VAL_FLAG            0xFF0000
#define DEF_INIT_SEATON_VAL_FLAG           0xFF000000

/* define for BR1285 errorcode Display control*/
#define ALARM_BR1285_EEPROM				BIT0
#define ALARM_BR1285_WARNING			BIT2
#define ALARM_BR1285_NOTCONCERN			BIT5

#define ZAPI_ERR_CODE_OFFSET            200

/*================================================[ public datatypes ]================================================*/

enum var_tbl_disp_options
{
	TRAVEL_SPD_CTRL_BIT = 0x0001,
	TRAVEL_SPD_DISP_BIT     = 0x0002,
	TILT_ANGLE_SENSOR_BIT = 0x0004,
	PIN_CODE_EN_BIT = 0x0008,
	AREA_SPEED_CTRL_BIT = 0x0010,
	STEERING_ANGLE_SENSOR = 0x0020,
	ULTRASONIC_SENSOR_BIT = 0x0040,
    SOC_DISPLAY_BIT = 0x0080,
	SEND_TSC_BIT = 0x4000,
	ANTI_THEFT_PROTECTION_BIT = 0x8000,
};



typedef void (* tMenuFunc)(void);
typedef u16 (*tLcdFunc)(u8 *str,s16 row,s16 column,u8 invert);
typedef void (* FaultPreActionFunc)(void);
typedef void (* FaultActionFunc)(u8 fault_index);

typedef struct sMenuItem * tMenuItem;
typedef struct sMenu * tMenu;


//struct sMenuItem
//{
//    u16          attr;                     // menu item attribute
//    SmallIcon    *SIcon;                   // Small icon
//    SmallIcon    *SIconHigh;               // highlight icon
//    char         *pszTitle;                // title
//    u8           rows;                     // row position
//    tMenuFunc    pfMenuFunc;               // call back function
//    tMenu        psSubMenu;                // sub menu
//    u16          langTitleIndex;           // language index
//    u32          object_id;                // Can object index 
//    u8           nDispIndex;               // Display index
//};

struct sMenu
{
    char         *pszTitle;
    tMenuItem    psItems;
    u8           nItems;	
    u8           DefaultMenuItem;
    u8           minItems;
    u8           maxItems;
    u16          langTitleIndex;
    u16          attr;
    u8           dispItems;
};



/*================================================[ public variables ]================================================*/
extern u32 fault_status;
extern u32 fault_status_prev;
extern u16 date_code;					    //	3
extern char disp_serial_number[];					//	4
extern s16 speedometer_units;               //  121 -   70 source\global_VCL_variables.c
extern s16 can2_canopen_system_status_flags;     //  683 -  561
extern s16 can2_nmt_state;                   //  685 -  563
extern u16 hardware_revision;               //
extern s8  LCD_Bklight;
extern u16 key_status_op;
extern u16 heater_on;
extern u16 key_status_op;

extern char part_number[];
extern u32 software_version;
extern u8 truck_type;
extern u16 DispDate;
extern u32 DispTime;
extern u16 error_reset;
extern const s16 MAX_KWP_ECU_OBJECT_DEF;
extern s16 (null)(void);

extern void *const kwp_data_variable_table[];
extern const u16 kwp_data_variable_attributes[];
extern const s16 MAX_KWP_DATA_OBJECT_DEF;
extern const s32 kwp_data_object_ids[];
extern const s16 kwp_data_var_tbl_index[];
extern u16 const kwp_data_ee_address_table[];


extern const int J1939_max_obj_id;

extern u32 active_osha_1;
extern u32 active_osha_2;
extern void *const osha_msg_table[];
extern u8 osha_msg_showed;
extern u8 total_osha_msg;
extern u8 osha_msg_show_index[];
extern u32 default_reset;
extern kwp_data_st kwp_data_params[];
extern const kwp_data_st kwp_ecu_params[];
extern u16 lcd_test;
extern const J1939_fault_msg_st  J1939_Fault_Msg_Descripiton[];
extern const int Menu_language_max_obj_id;
extern const Menu_language_st Menu_language_Descripiton[];


extern void *const speed_table[];

extern const Controller_fault_msg_st  E_Fault_Msg_Descripiton[];
extern const int E_fault_msg_max_obj_id;

extern const int traction_can_max_param_number;
extern CAN_param_st traction_can_param_table[]; 

extern const int pump_can_max_param_number;
extern CAN_param_st pump_can_param_table[]; 
extern const char *const UnitsTable[];
extern const Truck_fault_msg_st Display_Fault_Msg_Descripiton[];
extern const int display_fault_max_obj_id;
extern const s16 MAX_T1411_ENG_MAX_OBJECT_DEF;
extern const Truck_fault_msg_st  T1411_Engine_Fault_Msg_Descripiton[];
extern const s16 MAX_T1411_MAX_OBJECT_DEF;
extern const Truck_fault_msg_st  T1411_Fault_Msg_Descripiton[];
extern const char *const ErrorCodeInput[];
extern const char *const ErrorCodeInput1[];
extern const u8 CR2012_PinNo[];
extern const u8 CR7132_PinNo_input[];
extern const u8 CR7132_PinNo_Output[];
extern u16 brand_id;

extern const s16 MAX_BR1347_TRAC_MAX_OBJECT_DEF;
extern const Truck_fault_msg_st  BR1347_Trac_Fault_Msg_Descripiton[];
extern const s16 MAX_BR1347_LIFT_MAX_OBJECT_DEF;
extern const Truck_fault_msg_st  BR1347_Lift_Fault_Msg_Descripiton[];

extern const s16 MAX_BR1276_TRAC_MAX_OBJECT_DEF;
extern const Truck_fault_msg_st  BR1276_Trac_Fault_Msg_Descripiton[];
extern const s16 MAX_BR1276_LIFT_MAX_OBJECT_DEF;
extern const Truck_fault_msg_st  BR1276_Lift_Fault_Msg_Descripiton[];


extern s32 Eng_Speed;


extern const s16 MAX_KWP_GW_TRAC_ECU_OBJECT_DEF;
extern kwp_gateway_data_st kwp_gw_trac_ecu_params[]; 

extern const s16 MAX_KWP_GW_TRAC_DATA_OBJECT_DEF;
extern kwp_gateway_data_st kwp_gw_trac_data_params[];


extern const s16 MAX_KWP_GW_LIFT_ECU_OBJECT_DEF;
extern kwp_gateway_data_st kwp_gw_lift_ecu_params[]; 

extern const s16 MAX_KWP_GW_LIFT_DATA_OBJECT_DEF;
extern kwp_gateway_data_st kwp_gw_lift_data_params[];

extern char trac_ecu_name[];
extern u16 traction_battery_capacity;

extern u32 BR1285_part_number;

extern void *const steer_angle_table[];
extern u32 truck_id; 

extern volatile u16 key_up_value;
extern volatile u16 key_down_value;
extern volatile u16 key_enter_value;
extern volatile u16 key_up_time_value;
extern volatile u16 key_down_time_value;
extern s16 steer_angle;
extern const char*  const warning_str[];


extern char hardware_id[];
extern char truck_serial_number[];
extern char last_part_number[];
extern u16 truck_variant;

extern const s16 MAX_KWP_GW_TRAC_COMMON_OBJECT_DEF;
extern kwp_gateway_data_st kwp_gw_trac_common_params[];
extern const s16 MAX_KWP_GW_TRAC_CAL_OBJECT_DEF;
extern kwp_gateway_data_st kwp_gw_trac_cal_params[];

extern const s16 MAX_KWP_GW_LIFT_COMMON_OBJECT_DEF;
extern kwp_gateway_data_st kwp_gw_lift_common_params[];
extern const s16 MAX_KWP_GW_LIFT_CAL_OBJECT_DEF;
extern kwp_gateway_data_st kwp_gw_lift_cal_params[];


extern const int br1286_E_fault_msg_max_obj_id;

extern const Controller_fault_msg_st  br1286_E_Fault_Msg_Descripiton[];
extern const Truck_fault_msg_st  BR1275_BMS_Fault_Msg_Descripiton[];
extern const s16 MAX_BR1275_BMS_MAX_OBJECT_DEF;
extern u16 area_speed_limit;
extern const s16 MAX_RFID_MAX_OBJECT_DEF;
extern const Truck_fault_msg_st Rfid_Fault_Msg_Descripiton[];


extern u8 cal_stop;
extern s16 test_data;

extern s16 BDI_cutvpc;         // Param volts per cell at cutoff (0%) or actually 20% residual capacity 1.83 - 2.05 default 1.99
extern s16 BDI_mode;           // Param display mode for battery meter - options like % and HrsRem

extern u8 Language;
extern u16 ServicePresetHours;
extern u32 DateCurrent;
extern u32 TimeCurrent;
extern u8 ReferenceVoltage;
extern u32 ServiceByHours;
extern u8 CutOff;
extern u32 DigicodeArray1Value;
extern u32 DigicodeArray2Value;
extern u32 DigicodeArray3Value;
extern u32 DigicodeArray4Value;
extern u32 DigicodeArray5Value;
extern u32 DigicodeArray6Value;
extern u32 DigicodeArray7Value;
extern u32 DigicodeArray8Value;
extern u16 DigicodeAdministrator;
extern char software_id[13];
/*================================================[ inline functions ]================================================*/

/*================================================[ public functions ]================================================*/
#endif
/***********************************************************************************************************************
*                             Copyright 2016 Linde Material Handling. All rights reserved.                             *
***********************************************************************************************************************/


